import {createContext, useReducer,useContext} from "react"

const AppContext = createContext()

export const useAppContext = () => useContext(AppContext)

const appState = {
    username:"",
    pwd:"",

}

const AppReducer = (state,action)=>{
    switch(action.type) {
        case 'username':
            return {...state, username:action.username}
        case 'pwd':
            return {...state,pwd:action.pwd}
        default:
            return state;
    }
}

const AppProvider = ({children})=>{
    const [state,dispatch] = useReducer(AppReducer,appState);
    return (
        <AppContext.Provider
            value={
                {state,dispatch}
            }
        >
            {children}
        </AppContext.Provider>
    )
}

export default AppProvider;